"""
父进程中创建多个子进程
"""
from multiprocessing import Process
import os
from time import sleep

# def th1():
#     sleep(4)
#     print("吃饭")
#     print(os.getppid(),"--",os.getpid())
#
# def th2():
#     sleep(2)
#     print("睡觉")
#     print(os.getppid(),"--",os.getpid())
#
# def th3():
#     sleep(3)
#     print("打豆豆")
#     print(os.getppid(),"--",os.getpid())

def th(sec,info):
    sleep(sec)
    print(info)
    print(os.getppid(),"--",os.getpid())

if __name__ == '__main__':
    jobs = []
    # 循环创建进程
    for args in [(4,"吃饭"),(8,"睡觉"),(3,"打豆豆")]:
        p = Process(target=th,args=args)
        jobs.append(p)
        p.start()

    # 判定所有子进程结束
    for i in jobs:
        i.join()

    print("事情完成啦")